clear;clc;

% =========================================================================
%  LOAD DAT
% =========================================================================
% No Frictions
load NoFriction_fH0_x0.mat
pos_he = BINI<(1-theta)*exp(pini);
refi_prop_NoFriction  = mean(irf_refi_ypr(:,1));
refi_cprop_NoFriction = mean(irf_refi_ypr(pos_he,1));

% consumer Friction only
load NoFin_pf75_x0.mat
pos_he = BINI<(1-theta)*exp(pini);
refi_prop_consumer  = mean(irf_refi_ypr(:,1));
refi_cprop_consumer = mean(irf_refi_ypr(pos_he,1));

% lender Friction only
load NoFriction_fH0_x75.mat
pos_he = BINI<(1-theta)*exp(pini);
refi_prop_lender  = mean(irf_refi_ypr(:,1));
refi_cprop_lender = mean(irf_refi_ypr(pos_he,1));

% No FinTech
load NoFin_pf75_x75.mat
pos_he = BINI<(1-theta)*exp(pini);
refi_prop_NoFin  = mean(irf_refi_ypr(:,1));
refi_cprop_NoFin = mean(irf_refi_ypr(pos_he,1));

% FinTech w. spillovers (baseline)
load FinE_pq7_q5_pe6_e8.5_pf75_x75.mat
pos_he = BINI<(1-theta)*exp(pini);
refi_prop_FinE  = mean(irf_refi_ypr(:,1));
refi_cprop_FinE = mean(irf_refi_ypr(pos_he,1));

% Strong spillovers
load FinE_pq7_q5_pe60_e8.5_pf75_x75.mat
pos_he = BINI<(1-theta)*exp(pini);
refi_prop_FinEH  = mean(irf_refi_ypr(:,1));
refi_cprop_FinEH = mean(irf_refi_ypr(pos_he,1));


% =========================================================================
% Plot
% =========================================================================

prop =100*[refi_prop_NoFriction  refi_prop_lender refi_prop_consumer refi_prop_NoFin refi_prop_FinE refi_prop_FinEH];
cprop=100*[refi_cprop_NoFriction refi_cprop_lender refi_cprop_consumer refi_cprop_NoFin refi_cprop_FinE refi_cprop_FinEH];

cat = categorical({'No lender or consumer friction','Lender friction only','Consumer friction only','Both frictions','FinTech and networks (baseline)','Stronger network effects'});
cat = reordercats(cat,{'No lender or consumer friction','Lender friction only','Consumer friction only','Both frictions','FinTech and networks (baseline)','Stronger network effects'});

figure;
b=bar(cat,[cprop;prop]);
b(1).FaceColor='k';
b(2).FaceColor=[.8 .8 .8];
legend('Refi propensity, conditional on LTV<80%','Refi propensity, unconditional')
legend boxoff 
ylabel('Percent')
ylim([0 100])
